<?php
/**
 * Created by PhpStorm.
 * User: lingyun
 * Date: 2018/3/27
 * Time: 14:33
 * Desc: 原料库存日志管理
 */
namespace app\kuguan\controller;
use controller\BasicAdmin;
use service\DataService;
use think\Db;
use app\kuguan\model\MaterialModel;
use app\kuguan\model\GoodsMaterialModel;
use app\kuguan\model\MaterialStockModel;

class Materialstock extends BasicAdmin{
    /**
     * @Author  lingyun
     * @Desc    原料库存日志记录、
     * 2018-03-27
     */
    public function material_stock_log(){
        $this->title = "库存日志";
        $table = 'MaterialStockLog';
        $get = $this->request->get();

        $map = [];
        if(!empty($get['id'])){
            $map['a.material_id'] = ['eq',$get['id']];
            $this->assign('id',$get['id']);
            $material = db('goods_material')->where('id',$get['id'])->find();
        }else{
            $material = db('goods_material')->where('id',0)->find();
            $this->assign('id',0);
        }
        $map['a.receive_time'] = ['neq',''];
        if(!empty($get['sign'])){           //1进货，2生产，3报损
            $map['a.sign'] = ['eq',$get['sign']];
        }

        if(isset($get['date']) && $get['date'] !== '') {
            list($start, $end) = explode('-', str_replace(' ', '', $get['date']));
            $start = $start."  00:00:00";		$end = $end." 23:59:59";
            $start = strtotime($start);			$end = strtotime($end);
            $map['a.receive_time'] = array(array('gt',$start),array('lt',$end),'AND');
        }

        $db = Db::name('material_stock_log')->alias('a')->join('ys_goods_material b','a.material_id=b.id','LEFT')->where($map)->field('a.*,b.name')->order('a.id desc');
        $s_material = db('goods_material')->where(['is_deleted'=>0,'store_id'=>0])->select();        //选择的商品

        $this->assign('material',$material);
        $this->assign('s_material',$s_material);

        return parent::_list($db);
    }

    /**
     * @Author  lingyun
     * @Desc    导出原料库存日志
     * 2018-03-27
     */
    public function export_material_stock_log(){
        $post = input('param.');
        $model = new MaterialStockModel();
        $model->export_material_stock_log($post);
    }

}